home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / modelers / geomview / source.lha / Geomview / src / lib / geometry / hpoint3 / hline3.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-02-26  |  4.7 KB  |  252 lines

  1. /* Copyright (c) 1992 The Geometry Center; University of Minnesota
  2.    1300 South Second Street;  Minneapolis, MN  55454, USA;
  3.    
  4. This file is part of geomview/OOGL. geomview/OOGL is free software;
  5. you can redistribute it and/or modify it only under the terms given in
  6. the file COPYING, which you should have received along with this file.
  7. This and other related software may be obtained via anonymous ftp from
  8. geom.umn.edu; email: software@geom.umn.edu. */
  9.  
  10. /* Authors: Charlie Gunn, Pat Hanrahan, Stuart Levy, Tamara Munzner, Mark Phillips */
  11.  
  12. #
  13. /*
  14. **    hline3.c - procedural interface to 3D line geometry
  15. **
  16. **    pat hanrahan
  17. */
  18.  
  19. #include <math.h>
  20. #include "hg4.h"
  21. #include "hpoint3.h"
  22. #include "hplane3.h"
  23. #include "hline3.h"
  24. #include "transform3.h"
  25.  
  26. HLine3 *
  27. HLn3Create()
  28. {
  29.     return (HLine3 *) malloc( sizeof(HLine3) );
  30. }
  31.  
  32. void
  33. HLn3Delete( ln )
  34.     HLine3 *ln;
  35. {
  36.     free((char *)ln);
  37. }
  38.  
  39. void
  40. HLn3Print( ln )
  41.     HLine3 *ln;
  42. {
  43.     printf( "ln(%s) \n", ln->type == HLN3_POINT_FORM ? "pt" : "pl" );
  44.     Hg4Print2( ln->L );
  45. }
  46.  
  47. void
  48. HLn3Copy( ln1, ln2 )
  49.     HLine3 *ln1, *ln2;
  50. {
  51.     bcopy( (char *)ln1, (char *)ln2, sizeof(HLine3) );
  52. }
  53.  
  54. /*
  55. **    Form the anti-symmetric line tensor from two points.
  56. **
  57. **    Note: pt * L = pl.
  58. **    (1) pl is the plane formed from the line and the pt.
  59. **    (2) each col of L is a plane containing the line.
  60. **    (3) if pl is identically 0 then the pt lies on the line.
  61. */
  62. int
  63. HLn3From2HPt3s( ln, pt1, pt2 )
  64.     HLine3  *ln;
  65.     HPoint3 *pt1, *pt2;
  66. {
  67.     ln->type = HLN3_POINT_FORM;
  68.     Hg4AntiProductPiQj( ln->L, pt1, pt2 );
  69.  
  70.     return Hg4Undefined2( ln->L );
  71. }
  72.  
  73. /*
  74. **    Form the anti-symmetric line tensor from two planes.
  75. **
  76. **    Note: K * pl = pt.
  77. **    (1) pt is the point formed from the line and the pl.
  78. **    (2) each row of K is a point on the line.
  79. **    (3) if pt is identically 0 then the pl lies on the line.
  80. */
  81. int
  82. HLn3From2HPl3s( ln, pl1, pl2 )
  83.     HLine3  *ln;
  84.     HPlane3 *pl1, *pl2;
  85. {
  86.     ln->type = HLN3_PLANE_FORM;
  87.     Hg4AntiProductPiQj( ln->L, pl1, pl2 );
  88.  
  89.     return Hg4Undefined2( ln->L );
  90. }
  91.  
  92. int
  93. HLn3IntersectHPl3( ln, pl, pt )
  94.     HLine3 *ln;
  95.     HPlane3 *pl;
  96.     HPlane3 *pt;
  97. {
  98.     HLine3 aln;
  99.  
  100.     if( ln->type == HLN3_PLANE_FORM ) {
  101.     HLn3Dual( ln, &aln );
  102.     ln = &aln;
  103.     }
  104.     return Hg4Intersect2( ln->L, pl, pt );
  105. }
  106.  
  107. int
  108. HLn3IntersectHPt3( ln, pt, pl )
  109.     HLine3 *ln;
  110.     HPoint3 *pt;
  111.     HPlane3 *pl;
  112. {
  113.     HLine3 aln;
  114.  
  115.     if( ln->type == HLN3_POINT_FORM ) {
  116.     HLn3Dual( ln, &aln );
  117.     ln = &aln;
  118.     }
  119.     return Hg4Intersect2( ln->L, pt, pl );
  120. }
  121.  
  122.  
  123. /*
  124. **    predicate which tests for 3d line intersection and
  125. **    if an intersection is found returns the point at which th
  126. **    two lines cross and the plane in which the two lines lie.
  127. **    
  128. **    Note: One of the lines should be in the "plane-form" and the
  129. **    other in the "point-form."
  130. */
  131. int
  132. HLn3IntersectHLn3( ln1, ln2, pl, pt )
  133.     HLine3 *ln1, *ln2;
  134.     HPlane3 *pl;
  135.     HPoint3 *pt;
  136. {
  137.     HLine3 ln;
  138.  
  139.     if( ln1->type == ln2->type ) {
  140.     Hg4Dual( ln2, &ln );
  141.     ln2 = &ln;
  142.     }
  143.  
  144.     if( ln1->type == HLN3_POINT_FORM ) 
  145.     return Hg4Intersect4( ln1->L, ln2->L, pt, pl );
  146.     else
  147.     return Hg4Intersect4( ln1->L, ln2->L, pl, pt );
  148. }
  149.  
  150. int
  151. HLn3Undefined( ln )
  152.     HLine3 *ln;
  153. {
  154.     return Hg4Undefined2( ln->L );
  155. }
  156.  
  157. int
  158. HLn3Infinity( ln )
  159.     HLine3 *ln;
  160. {
  161.     return Hg4Infinity2( ln->L, ln->type == HLN3_PLANE_FORM );
  162. }
  163.  
  164. int
  165. HLn3Compare( ln1, ln2 )
  166.     HLine3 *ln1, *ln2;
  167. {
  168.     /* Do the types have to agree? */
  169.     return Hg4Compare2( ln1->L, ln2->L );
  170. }
  171.  
  172. int 
  173. HLn3CoincidentHPt3( ln, pt )
  174.     HLine3 *ln;
  175.     HPoint3 *pt;
  176. {
  177.     HPlane3 pl;
  178.  
  179.     return HLn3IntersectHPt3( ln, pt, &pl );
  180. }
  181.  
  182. int
  183. HLn3CoincidentHLn3( ln1, ln2 )
  184.     HLine3 *ln1, *ln2;
  185. {
  186.     HPlane3 pl;
  187.     HPoint3 pt;
  188.  
  189.     if( HLn3IntersectHLn3( ln1, ln2, &pl, &pt ) )
  190.     return HPl3Undefined( &pl );
  191.     return 0;
  192. }
  193.  
  194. int 
  195. HLn3CoincidentHPl3( ln, pl )
  196.     HLine3 *ln;
  197.     HPlane3 *pl;
  198. {
  199.     HPoint3 pt;
  200.  
  201.     return HLn3IntersectHPl3( ln, pl, &pt );
  202. }
  203.  
  204.  
  205. void
  206. HLn3Transform( T, ln1, ln2 )
  207.     Transform3 T;
  208.     HLine3 *ln1, *ln2;
  209. {
  210.     /* Assume T is a point transform */
  211.     if( ln1->type == HLN3_PLANE_FORM ) {
  212.     HLn3Dual( ln1, ln2 );
  213.     Hg4Transform2( T, ln2->L, ln2->L );
  214.     HLn3Dual( ln2, ln2 );
  215.     }
  216.     else {
  217.     Hg4Transform2( T, ln1->L, ln2->L );
  218.     ln2->type = ln1->type;
  219.     }
  220. }
  221.  
  222. /*
  223. **    Convert the matrix formed from planes/points to that formed
  224. **    from points/planes.
  225. **
  226. **    Note:
  227. **    (1) pu-qt+sr=0.
  228. **    (2) (s,q,p,0) is parallel to the line.
  229. **    (3) (-r,t,-u,0) is a plane containing the line and the origin.
  230. **    (4) K*L = 0.
  231. */
  232. void
  233. HLn3Dual( ln, lndual )
  234.     HLine3 *ln, *lndual;
  235. {
  236.     Hg4Dual( ln->L, lndual->L );
  237.     lndual->type = HLN3_DUAL_FORM(ln->type);
  238. }
  239.  
  240. void
  241. HLn3Perp( ln, lnperp )
  242.     HLine3 *ln, *lnperp;
  243. {
  244.     HPoint3 pt;
  245.     HPlane3 pl;
  246.  
  247.     /* LnIntersectPl( ln, &HPl3Ideal, &pt ); */
  248.     HPt3Copy( ln->L[3], &pt );
  249.     HPt3Dual( &pt, &pl );
  250.     HLn3From2HPl3s( lnperp, &pl, &HPl3Ideal );
  251. }
  252.